package com.google.samples.apps.databinging.recycler

import android.view.View
import android.widget.Toast
import com.chad.library.adapter.base.BaseBinderAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.samples.apps.databinging.R
import com.google.samples.apps.databinging.binding.Book
import com.google.samples.apps.databinging.databinding.LayoutItemBookBinding

/**
 * Created by Administrator on 2021/7/10 0010.
 * Describe:
 */
class QBookAdapter :
    BaseQuickAdapter<Book, BaseDataBindingHolder<LayoutItemBookBinding>>(R.layout.layout_item_book) {

    val bookListener = BookListener()

    override fun convert(holder: BaseDataBindingHolder<LayoutItemBookBinding>, item: Book) {
        holder.dataBinding?.run {
            book = item
            listener = bookListener
            executePendingBindings()
        }
    }

    class BookListener {
        fun onClick(view: View, item: Book) {
            Toast.makeText(view.context, "$item", Toast.LENGTH_SHORT).show()
        }
    }
}